Skip to content

Add PhysioNet2019Dataset for hourly ICU sepsis time series - #1790

Merged
solarsys merged 1 commit into
sunlabuiuc:masterfrom
yuema-git:feat/physionet2019-dataset
Dec 3, 2026
Merged

solarsys merged 1 commit into
sunlabuiuc:masterfrom
yuema-git:feat/physionet2019-dataset

Conversation

@yuema-git

Copy link
Copy Markdown
Contributor

Part of #1789

Summary

Adds PhysioNet2019Dataset for the open-access PhysioNet/Computing in Cardiology Challenge 2019 ICU sepsis dataset (Reyna et al., Critical Care Medicine 2020), filling the PhysioNet 2019 dataset gap noted in #1605 / BTY-49.

Key Design Decisions

  • Three separated tables (events, labels, patients):
    • events: non-NaN hourly vital-sign and laboratory observations only (hour, parameter, value), keeping SepsisLabel strictly isolated from input features.
    • labels: one row per patient-hour (hour, sepsis_label), preserving hours where all 34 dynamic variables are NaN (e.g., hour 1 of p000001.psv).
    • patients: one row per ICU stay holding hospital ("A" or "B"), static admission descriptors, num_hours, sepsis, and first_sepsis_hour.
  • Lossless raw NaN at the dataset layer: Laboratory tests average 94.8% hourly missingness with strong informative missingness (MNAR). No forced forward-fill or imputation is applied during ingestion so downstream tasks can configure missingness handling per model family.
  • Reusable wide-to-long parser & streaming build: parse_wide_hourly_record accepts configurable column roles/delimiters, and prepare_physionet2019 streams .psv stays directly into atomic .tmp CSVs rather than buffering >10M rows in memory.
  • Manifest-driven download: download_physionet2019 parses the official SHA256SUMS.txt manifest, skips existing files, and supports an injectable fetcher for offline unit testing.

File Guide

  • pyhealth/datasets/physionet2019.py: Dataset class, variable group constants (VITAL_VARIABLES, LAB_VARIABLES, DYNAMIC_VARIABLES, STATIC_VARIABLES), download_physionet2019, parse_wide_hourly_record, and prepare_physionet2019.
  • pyhealth/datasets/configs/physionet2019.yaml: Three-table dataset configuration.
  • pyhealth/datasets/__init__.py: Export PhysioNet2019Dataset.
  • tests/core/test_physionet2019.py: 10 fast offline unit tests using synthetic .psv stays in tmp_path.
  • docs/api/datasets/pyhealth.datasets.PhysioNet2019Dataset.rst & docs/api/datasets.rst: Sphinx API reference and dataset index entries.

Testing & Verification

  • pytest tests/core/test_physionet2019.py -v: 10 passed (offline synthetic fixtures).
  • python tools/check_pr_rules.py --base upstream/master --head HEAD: All PR contribution rules passed.
  • Full-dataset local smoke check on all 40,336 real .psv stays (training_setA + training_setB): built patients.csv (40,336 rows, 1.5 MB), labels.csv (1,552,210 rows, 50.0 MB), and events.csv (10,486,913 rows, 419.2 MB) in 17.3s.

Disclosure

AI coding assistance was used during implementation and test drafting; all design decisions, code paths, and test assertions were reviewed and verified manually.

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

Test Coverage

Total: 89.32% (65464 / 73288 lines)

Modified file Coverage Lines
pyhealth/datasets/__init__.py 100.00% 96 / 96
pyhealth/datasets/physionet2019.py 89.09% 196 / 220

Workflow run · d101cd1

@solarsys solarsys added the status: automatic The PR will go through automatic review process. label Dec 2, 2026 — with Claude

solarsys commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

/review


Generated by Claude Code

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed commit d101cd1

continue
dest = root_path / match.group(1)
if not dest.exists():
tasks.append((base + rel, dest))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low] SHA256SUMS hashes are downloaded but never verified

download_physionet2019 reads the SHA256SUMS.txt manifest only to list file names. The per-file digests it contains are never compared with the downloaded files, so a corrupted or truncated .psv would be used silently and later skipped by the dest.exists() check. Consider verifying each file's SHA-256 against the manifest after download, as pyhealth/models/generators/synthea.py does for its jar. If verification is not added, the docstring should say it does not check integrity.

logger.info("Downloading %d PhysioNet 2019 files into %s", len(tasks), root_path)
with concurrent.futures.ThreadPoolExecutor(max_workers=max_workers) as pool:
futures = [pool.submit(_run_fetch, url, dest) for url, dest in tasks]
for fut in concurrent.futures.as_completed(futures):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low] A failed download waits for every queued file before raising

The loop calls fut.result() on the first failure, but the surrounding ThreadPoolExecutor with block then waits for all remaining queued futures. A network outage early in the run would therefore keep fetching or retrying up to ~40k files before the error surfaces. Cancel the pending futures (for example, call pool.shutdown(cancel_futures=True) or cancel each future) when one fails.

selected_sets = _normalize_sets(sets)
if download:
download_physionet2019(root_path, sets=selected_sets)
if not all(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low] Cached CSV tables silently ignore a changed sets argument

If the three CSVs already exist, sets is ignored: PhysioNet2019Dataset(root, sets=('B',)) returns patients from both hospitals if the tables were built earlier. The limitation is documented only in the class docstring. Consider adding a line to the rst page, or logging a warning when the requested sets differ from the built ones. PhysioNet2012Dataset behaves the same way, so this need not block the merge.

]
assert hourly_labels == [(1, 0), (2, 0), (3, 1)]

def test_negative_patient_and_iculos_starting_gt_1(self, tmp_path: Path) -> None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low] Test name does not match what the test checks

test_negative_patient_and_iculos_starting_gt_1 uses no negative patient ID. It checks that a stay starting at ICULOS 4 and a negative HospAdmTime are parsed. Rename it to something like test_stay_starting_after_hour_one_keeps_hour_numbers.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Review

suggestion: approve
decision: approve

Thank you for contributing PhysioNet2019Dataset. It adds the open-access PhysioNet/CinC 2019 ICU sepsis data, with separate events, labels and patients tables, a manifest-driven download and a streaming table builder. This looks ready to merge.

The change is self-contained. It subclasses BaseDataset without modifying it, and the only shared code it uses is the existing download_file utility, which it doesn't change. Adding the export to __init__.py is registration. The dataset cites its source and paper in the docstring and docs, and the docs match the code.

Coverage is above the bar. physionet2019.py is at 89.09%, against the 80% guideline for each file. The whole repository is at 89.32%, against the 60% bar.

Optional suggestions:

  • SHA256SUMS.txt is fetched but the hashes are never checked. You could verify each downloaded file against it.
  • If one download fails, the executor still waits for all the queued downloads before the error is raised. Cancelling the pending futures on the first failure would surface it sooner.
  • If sets is changed after the CSVs are built, the cached CSVs are reused silently. This is only noted in the class docstring. A log warning, or a note in the docs page, would help.
  • test_negative_patient_and_iculos_starting_gt_1 doesn't test a negative patient. Renaming it would make its purpose clearer.
  • The default HTTP path with retries, and the sets validation, have no tests.

Reviewed commit d101cd1

@solarsys
solarsys merged commit 3459aef into sunlabuiuc:master Dec 3, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: automatic The PR will go through automatic review process.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants